package cn.flkj.gmca.ca.gmca.gmcautil;

import org.bouncycastle.util.encoders.Base64;

import javax.security.auth.x500.X500Principal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : 州长在手 2020/12/15 上午9:13
 */
public class CAUtil {

    public static String getPriKeyMD5() {
        return "53C9768B789BB267CCAEEDA53EEEC541";
    }

    public static String getCertMD5() {
        return "234958FCB7F8FC7B9C2DBEE642F85161";
    }

    public static byte[] getPriKey() {
        String priKey = "MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgSHQzbItkQmgUAjTwIVgM7HrDluC2kNTrCjiHNP8hpTKhRANCAAQxYzvW694hJ0AT+bSxYw5aWNHAuA4VMcSkgAGWdKO0F00vZ5mj68f8lEKT2QxH+2gE3vfpXyB+De29J60tjls/";
        return Base64.decode(priKey.getBytes());
    }

    public static byte[] getCert() {
        String cert = "MIICjTCCAjSgAwIBAgIRAL7wvNqdYWeAiWK8JR46lLgwCgYIKoEcz1UBg3UwgZcxCzAJBgNVBAYTAkNOMQ8wDQYDVQQIEwZGdWppYW4xDzANBgNVBAcTBkZ1emhvdTEcMBoGA1UEChMTZHNqZnd6eC5mdWNoYWluLmNvbTEnMCUGA1UECwwe56aP5bee5biC5aSn5pWw5o2u5pyN5Yqh5Lit5b+DMR8wHQYDVQQDExZjYS5kc2pmd3p4LmZ1Y2hhaW4uY29tMB4XDTIwMDcxNDA4NTQ1N1oXDTMwMDcxMjA4NTQ1N1owgZcxCzAJBgNVBAYTAkNOMQ8wDQYDVQQIEwZGdWppYW4xDzANBgNVBAcTBkZ1emhvdTEcMBoGA1UEChMTZHNqZnd6eC5mdWNoYWluLmNvbTEnMCUGA1UECwwe56aP5bee5biC5aSn5pWw5o2u5pyN5Yqh5Lit5b+DMR8wHQYDVQQDExZjYS5kc2pmd3p4LmZ1Y2hhaW4uY29tMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEMWM71uveISdAE/m0sWMOWljRwLgOFTHEpIABlnSjtBdNL2eZo+vH/JRCk9kMR/toBN736V8gfg3tvSetLY5bP6NfMF0wDgYDVR0PAQH/BAQDAgGmMA8GA1UdJQQIMAYGBFUdJQAwDwYDVR0TAQH/BAUwAwEB/zApBgNVHQ4EIgQgR0NMIEM6X9R/QIyWYuIv9bNCgKnJLsOXdQMKD+2aXTIwCgYIKoEcz1UBg3UDRwAwRAIgFd/vJLEqcu7C+17I86RWp5EtJTvwlLdTEF7BLsKJ/hUCIBDHnH5BJoVoIniYfuuTHPokTdPmnLj2bxJsGfLQ00bl";
        return Base64.decode(cert.getBytes());
    }

    public static Map<String, String> parseIssuerX500Principal(X500Principal x500Principal) {
        String name = x500Principal.getName();
        Map<String, String> map = new HashMap<String, String>();
        map.put("CN", name.substring(name.indexOf("CN=") + 3,
                name.indexOf(",", name.indexOf("CN="))));
        map.put("OU", name.substring(name.indexOf("OU=") + 3,
                name.indexOf(",", name.indexOf("OU="))));
        map.put("O", name.substring(name.indexOf("O=") + 2,
                name.indexOf(",", name.indexOf("O="))));
        map.put("L", name.substring(name.indexOf("L=") + 2,
                name.indexOf(",", name.indexOf("L="))));
        map.put("ST", name.substring(name.indexOf("ST=") + 3,
                name.indexOf(",", name.indexOf("ST="))));
        map.put("C", name.substring(name.indexOf("C=") + 2));
        return map;
    }
}
